<template>
	<view class="addbox">
		<u-navbar title="幸运币充值"></u-navbar>
		<view class="luckynum">
			{{list.user_prize_integral}}
		</view>
		<view class="luckyname">
			我的幸运币
		</view>
		<view class="amount">
			<view class="amountitle">选择充值金额</view>
			<view class="amountcont">
				<view class="dangejine" v-for="(item,index) in title" :key="item.id" :class="{'selectjin':currentSort==index}" @click="active(index,item.num)">
					<view class="jinelogo">
						<image src="../../static/xr.png" class="iconlucky" mode=""></image>
						<text>{{item.num}}</text>
					</view>
					<view class="jine">{{list.integral_rmb?((item.num)*Number(list.integral_rmb)).toFixed(2):''}}元</view>				
				</view>				
			</view>
		</view>
		<view class="payment">
			选择支付方式
		</view>
		<view class="twopay">
			<view class="paybtn" :class="{'selectpaybtn':wxBtn}" @click="weixinbtn">微信支付</view>
			<!-- #ifdef APP-PLUS -->
				<view class="paybtn" :class="{'selectpaybtn':zfbBtn}" @click="zfbbtn">支付宝支付</view>
			<!-- #endif -->
		</view>
		<view class="bottom">
			<view class="payamount">￥{{list.integral_rmb?num*Number(list.integral_rmb):''}}</view>
			<view @click="submit" class="conpay">确认支付</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list:'',
				paymode: '',
				currentSort:0,
				wxBtn:true,
				zfbBtn:false,
				// #ifdef MP-WEIXIN || H5
				paymode:'wechat',
				// #endif
				
				// #ifdef APP-PLUS
				paymode:'alipay',
				// #endif
				title:[
					{id:1,num:25,},
					{id:2,num:50,},
					{id:3,num:100,},
					{id:4,num:300,},
					{id:5,num:500,},
					{id:6,num:1000,},
				],
				num:25,
				realPay:25,//金额
				integral_rmb:0,  //倍率
				is_virtual:0   //1虚拟  0真实
			}
		},
		onLoad() {
			this.post()
		},
		methods: {
			active(index,num) {
				 this.currentSort  =  index ? index :0;
				 this.num = num ? num : 25;
				 // console.log(this.integral_rmb,'this.integral_rmb',this.num);
				 this.realPay = this.num * this.integral_rmb
				 // console.log(this.realPay);
			},
			weixinbtn(){
				this.zfbBtn = false
				this.wxBtn = true
				this.paymode = 'wechat'
			},
			zfbbtn(){
				this.wxBtn = false
				this.zfbBtn = true
				this.paymode = 'alipay'
			},
			post(){
				this.$http({
					url: 'api/member/integral_index'
				}).then(res => {
					this.list = res.data.data
					this.integral_rmb = Number(res.data.data.integral_rmb) 
					this.is_virtual = res.data.data.is_virtual
					// console.log(this.is_virtual);
					// this.codeShareUrl 
					this.active()
				})
			},
			// 钱购买
			submit() {
				if (this.paymode == "") {
					this.$tip.tip("请选择支付方式")
					return
				}
				if(this.is_virtual == 0){  //真实支付
					this.$http({
						url: "api/pay/go_recharge",
						data: {
							num: this.realPay,
							paymode:this.paymode,
							desc: '',
							address_id:'',
							// #ifdef H5
							client: 0,
							// #endif
							// #ifdef MP-WEIXIN
							client: 1,
							// #endif
							// #ifdef APP-PLUS
							client: 2,
							// #endif
						}
					}).then(res => {
						if (res.data.code == 1) {
							// #ifdef H5
							this.fun.go_h5pay(res.data.data);
							// #endif
							
							// #ifdef MP-WEIXIN
							this.fun.go_mpwxpay(res.data.data).then(payres => {
								this.$tip.tip("支付成功", "success")
								setTimeout(() => {
									uni.redirectTo({
										url: '/pages/mall/paySuccexx'
									})
								}, 700)
							}).catch(payerr => {
								this.$tip.tip('支付失败')
							});
							// #endif
							
							// #ifdef APP-PLUS
							if(this.paymode=='wechat'){
								this.fun.go_appwxpay(res.data.data.pay_data).then(payres => {
									this.$tip.tip("支付成功", "success") 
									setTimeout(() => {
										uni.redirectTo({
											url: '/pages/mall/paySuccexx'
										})
									}, 700)
								}).catch(payerr => {
									this.$tip.tip('支付失败')
								});
							}else{
								this.fun.go_appalipay(res.data.data.pay_data).then(payres => {
									this.$tip.tip("支付成功", "success") 
									setTimeout(() => {
										uni.redirectTo({
											url: '/pages/mall/paySuccexx'
										})
									}, 700)
								}).catch(payerr => {
									this.$tip.tip('支付失败')
								});
							}
							// #endif
						}else if(res.data.code == 8){ //0元免支付的
							uni.redirectTo({
								url: '/pages/mall/paySuccexx'
							})
						} else {
							this.$tip.tip(res.data.msg)
						}
					
					}).catch(err => {});
					return;
				}else if(this.is_virtual == 1){
					uni.navigateTo({
						url: '/pagesA/pages/my/xuniPay?realPay='+this.realPay
					});
				}else{
					uni.showToast({
						icon:'none',
						title:'出错了'
					})
				}
			},
			get_sys_bank(){
				
			},
			get_my_bank(){
				
			},
			getUser() {
				
			},

		}
	}
</script>

<style lang="scss" scoped>
	.addbox{
		width: 100vw;
		height: 100vh;
		background-image: url('../../static/TopupBg.png');
		background-size: 750rpx 700rpx;
		background-repeat: no-repeat;
		background-color: #f6f6f6;
		position: relative;
		.luckynum{
			color: #3D3D3D;
			font-size: 80rpx;
			font-weight: bold;
			text-align: center;
			padding:120rpx 0 20rpx;
		}
		.luckyname{
			font-size: 24rpx;
			font-weight: 500;
			text-align: center;
			color: #000000;
		}
		.amount{
			width: 686rpx;
			height: 441rpx;
			border-radius: 18rpx;
			margin: 58rpx auto;
			background: #fff;
			display: flex;
			flex-direction: column;
			.amountitle{
				margin-top: 35rpx;
				margin-left: 35rpx;
			}
			.amountcont{
				width: 686rpx;
				height: 344rpx;
				display: flex;
				flex-wrap: wrap;
				.selectjin{
					color: #A947CA;
					border: 2rpx solid #A947CA;
					background: linear-gradient(180deg, #C9B9F3 0%, #FFFFFF 100%) !important;
				}
				.dangejine{
					width: 191rpx;
					height: 140rpx;
					text-align: center;
					border-radius: 12rpx;
					background: #f3f3f3;
					margin: 18rpx;
					.jinelogo{
						font-size: 36rpx;
						font-weight: bold;
						padding-top: 30rpx;
						.iconlucky{
							display: inline-block;
							width: 30rpx;
							height: 30rpx;
							padding-right: 10rpx;
						}
					}
					.jine{
						font-size: 20rpx;
						color: #666666;
						font-weight: 500;
						padding-top: 14rpx;
					}
				}
			}
		}
		.payment{
			padding-left: 68rpx;
		}
		.twopay{
			padding-left: 44rpx;
			display: flex;
			.paybtn{
				width: 191rpx;
				height: 85rpx;
				line-height: 83rpx;
				text-align: center;
				font-weight: 500;
				font-size: 24rpx;
				margin: 25rpx;
				border-radius: 12rpx;
				background: #FFFFFF;
				border: 2rpx solid #FFFFFF;
			}
			.selectpaybtn{
				color: #A947CA;
				border: 2rpx solid #A947CA;
			}
		}
		.bottom{
			position: absolute;
			left: 0;
			bottom: 0;
			width: 750rpx;
			height: 128rpx;
			line-height: 128rpx;
			background: #FFFFFF;
			display: flex;
			.payamount{
				font-size: 50rpx;
				font-weight: bold;
				margin-left: 50rpx;
			}
			.conpay{
				width: 410rpx;
				height: 88rpx;
				line-height: 88rpx;
				border-radius: 12rpx;
				font-size: 28rpx;
				color: #FFFFFF;
				background: linear-gradient(81deg, #3B70EC 4%, #AE84F5 95%);
				margin: auto 0;
				margin-left: 60rpx;
				text-align: center;
			}
		}
	}
</style>
